package ptumall.utils;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultVO<T> {
    private static final String SUCCESS = "0";
    private static final String ERROR = "1";
    private String code;

    private String msg;

    private T data;

    //    自定义方法
    public static ResultVO success() {
//        创建了一个Result对象
        ResultVO result = new ResultVO();
        result.setCode(SUCCESS); // 把success的值设置为code的值
        return result;
    }

    public static ResultVO success(Object data) {
        ResultVO result = new ResultVO();
//      设置code 和数据
        result.setCode(SUCCESS);
        result.setData(data);
        return result;
    }

    public static ResultVO error(String msg) {
        ResultVO result = new ResultVO();
//        设置code值和报错信息
        result.setCode(ERROR);
        result.setMsg(msg);
        return result;
    }
}
